package model01;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ReadBinaryFromFile {
	public static void main(String[] args) {
		String strVal = null;
		int iVal = 0;
		float fVal = 0.0f;
		double dVal = 0.0;
		
		DataInputStream dis;
		FileInputStream fis;
		
		try {
			//mo file, neu khong co se nem Exception FileNotFound ra
			fis = new FileInputStream("binaryfile.dat");
			dis = new DataInputStream(fis);
			
			//doc du lieu tu file va xuat ra man hinh
			try {
				strVal = dis.readUTF();
				System.out.println("Kieu String: " + strVal);
				
				iVal = dis.readInt();
				System.out.println("Kieu int: " + iVal);
				
				fVal = dis.readFloat();
				System.out.println("Kieu float: " + fVal);
				
				dVal = dis.readDouble();
				System.out.println("Kieu double: " + dVal);
				
			} catch (IOException e) {
				e.printStackTrace();
			}

			//dong stream
			try {
				dis.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

}
